/*
 * Decompiled with CFR 0.150.
 * 
 * Could not load the following classes:
 *  cn.hutool.core.util.ObjectUtil
 *  de.felixroske.jfxsupport.FXMLController
 *  javafx.beans.value.ChangeListener
 *  javafx.beans.value.ObservableValue
 *  javafx.fxml.FXML
 *  javafx.fxml.Initializable
 *  javafx.scene.control.TextField
 *  javafx.scene.layout.AnchorPane
 *  org.springframework.beans.factory.annotation.Autowired
 */
package com.gys.controller.salesReceipts;

import cn.hutool.core.util.ObjectUtil;
import com.gys.common.util.ValidationUtil;
import com.gys.controller.BaseController;
import com.gys.controller.dataManger.ControllerManger;
import com.gys.controller.salesReceipts.SpliteProController;
import de.felixroske.jfxsupport.FXMLController;
import java.net.URL;
import java.util.ResourceBundle;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.TextField;
import javafx.scene.layout.AnchorPane;
import org.springframework.beans.factory.annotation.Autowired;

@FXMLController
public class ChangePriceByPersionController
extends BaseController
implements Initializable {
    @FXML
    private TextField price;
    @FXML
    private AnchorPane pane;
    @Autowired
    private SpliteProController spliteProController;

    public void initialize(URL location, ResourceBundle resources) {
        ControllerManger.controllerMap.put(this.getClass().getSimpleName(), this);
        this.init();
    }

    @Override
    public void init() {
        if (ObjectUtil.isEmpty(this.pane)) {
            return;
        }
        this.price.clear();
        this.price.textProperty().addListener((ChangeListener)new ChangeListener<String>(){

            public void changed(ObservableValue<? extends String> observable, String oldValue, String newValue) {
                if (ObjectUtil.isEmpty(newValue)) {
                    ChangePriceByPersionController.this.price.clear();
                    return;
                }
                if (!ValidationUtil.checkPositiveNumberGtZero2F(newValue) || newValue.length() > 8) {
                    ChangePriceByPersionController.this.price.setText(oldValue);
                    return;
                }
            }
        });
    }

    @FXML
    private void sureAction() {
        this.price.setText(String.format("%.2f", Float.valueOf(this.price.getText())));
        this.spliteProController.getAfterSplitePrice().setText(this.price.getText());
        this.spliteProController.changePriceByPersion = true;
        this.cancelAction();
    }

    @FXML
    private void cancelAction() {
        this.pane.getScene().getWindow().hide();
    }
}

